package Offer;

/**
 * 翻转单词顺序
 * @author 是阿秋啊
 * @date 2022/04/11 17:47
 **/
public class Num58 {
    public static String reverseWords(String s) {
        String[] str = s.trim().split(" ");
        StringBuilder sb = new StringBuilder();
        for (int i = str.length - 1; i >= 0; i--) {
            if (str[i].equals("")) continue;;
            if (i == 0) {
                sb.append(str[i]);
            } else {
                sb.append(str[i]).append(" ");
            }
        }
        return sb.toString();
    }
}
